package com.edu.scau.com.zhaoguangfeng.singlemodel;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class MultitionPatternDemo {

	private static AtomicInteger counter;
	private String name  ;
	private final  static int MAXNUMBER = 10 ;
	private static ArrayList<MultitionPatternDemo> list = new 
			ArrayList<MultitionPatternDemo>(MAXNUMBER);
	
	private MultitionPatternDemo(String name) {
		this.name = name ;
	}
	
	public static synchronized MultitionPatternDemo getInstance(String name) {
		MultitionPatternDemo m = null ;
		
		if(counter.get() < MAXNUMBER) {
			 m = new MultitionPatternDemo(name) ;
			list.add(m);
			counter.incrementAndGet();
			return m ;
		}
		
		return list.get(0);
	}

	public String getName() {
		return name;
	}
	
	
	
}
